#include <buola/gui.h>

#include <buola/gui/cicon.h>

#include <buola/widgets/ctbrenderer.h>
#include <buola/widgets/ctreebox.h>

namespace buola { namespace gui {

CTBRenderer::CTBRenderer(CTreeBox *pTreeBox)
{
    mTreeBox=pTreeBox;
}

CTBRenderer::~CTBRenderer()
{
}

CTreeBox::SNode *CTBRenderer::GetNodeAt(const CPoint_d &pPoint,int *pType)
{
    if(!mTreeBox->GetNodeCount()) return nullptr;
    
    for(CTreeBox::SNode *lNode=mTreeBox->GetNodes()[0];lNode;lNode=lNode->mNextVisible)
    {
        int lType=HitTestNode(lNode,pPoint);

        if(lType&LBHT_SELECT)
        {
            if(pType) *pType=lType;
            return lNode;
        }
    }
    
    return nullptr;
}

int CTBRenderer::GetNodesIn(const CRect_d &pRect,CTreeBox::SNode *pNodes[])
{
    int lNumNodes=0;

    for(int i=0;i<mTreeBox->GetNodeCount();i++)
    {
        CTreeBox::SNode *lI=mTreeBox->GetNodes()[i];
        
        if(HitTestNode(lI,pRect))
            pNodes[lNumNodes++]=lI;
    }
    
    return lNumNodes;
}

/*namespace gui*/ } /*namespace buola*/ }
